package com.tucy.logistics.security.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tucy.logistics.security.pojo.LoginDto;
import com.tucy.logistics.common.entity.user.SystemUser;
import com.tucy.logistics.common.result.Result;
import com.tucy.logistics.security.pojo.TokenDetails;
import com.tucy.logistics.security.pojo.UserDto;
import com.tucy.logistics.security.service.SystemUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * author: tcy
 * createDate: 2023/7/31
 * description:
 */
@Api(tags = "用户操作")
@RestController
@RequestMapping("/user")
public class SystemUserController {

    @Autowired
    SystemUserService systemUserService;

    @ApiOperation(value = "系统RSA密钥",notes = "用户操作")
    @GetMapping("/secretKey")
    public Result<Map<String, String>> secretKey(){
        return Result.success(systemUserService.secretKey());
    }

    @ApiOperation(value = "系统注册",notes = "用户操作")
    @PostMapping("/normalRegistration")
    public Result<Boolean> normalRegistration(@RequestBody SystemUser user){
        return Result.success(systemUserService.normalRegistration(user));
    }

    @ApiOperation(value = "系统登录",notes = "用户操作")
    @PostMapping("/login")
    public Result<TokenDetails> login(@RequestBody LoginDto dto){
        return Result.success(systemUserService.login(dto));
    }

    @ApiOperation(value = "注销登录",notes = "用户操作")
    @GetMapping("/loginOut")
    public Result<String> loginOut(){
        return Result.success(systemUserService.loginOut());
    }

    @ApiOperation(value = "校验登录",notes = "用户操作")
    @GetMapping("/checkLogin")
    public Result<Boolean> checkLogin(){
        return Result.success(systemUserService.checkLogin());
    }

    @ApiOperation(value = "修改密码",notes = "用户操作")
    @PostMapping("/updatePassword")
    public Result<Boolean> updatePassword(@RequestBody LoginDto loginDto){
        return Result.success(systemUserService.updatePassword(loginDto));
    }

    @ApiOperation(value = "注销账号",notes = "用户操作")
    @PostMapping("/logOutAccount")
    public Result<Boolean> logOutAccount(@RequestBody LoginDto loginDto){
        return Result.success(systemUserService.logOutAccount(loginDto));
    }

    @ApiOperation(value = "用户查询",notes = "用户操作")
    @PostMapping("/queryUsers")
    public Result<Page<SystemUser>> queryUsers(@RequestBody UserDto userDto){
        return Result.success(systemUserService.queryUsers(userDto));
    }

}
